From fc5abf10bfdbd30a80cf6f640d3ad9959eb2871c Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 7 Apr 2015 16:56:45 -0700 Subject: [PATCH] Don't run doc tests if there's a filter --- src/cargo/ops/cargo_test.rs | 9 ++++++++- tests/test_cargo_test.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/cargo/ops/cargo_test.rs b/src/cargo/ops/cargo_test.rs index a5993284e..bc2efd22c 100644 --- a/src/cargo/ops/cargo_test.rs +++ b/src/cargo/ops/cargo_test.rs @@ -20,7 +20,14 @@ pub fn run_tests(manifest_path: &Path, Err(e) => return Ok(Some(e)), }; - if options.no_run { return Ok(None) } + // If a specific test was requested or we're not running any tests at all, + // don't run any doc tests. + if let ops::CompileFilter::Only { .. } = options.compile_opts.filter { + return Ok(None) + } + if options.no_run { + return Ok(None) + } let libs = compile.package.targets().iter() .filter(|t| t.doctested()) diff --git a/tests/test_cargo_test.rs b/tests/test_cargo_test.rs index c237896c1..d57c06829 100644 --- a/tests/test_cargo_test.rs +++ b/tests/test_cargo_test.rs @@ -1445,3 +1445,31 @@ test!(doctest_dev_dep { assert_that(p.cargo_process("test").arg("-v"), execs().with_status(0)); }); + +test!(filter_no_doc_tests { + let p = project("foo") + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + "#) + .file("src/lib.rs", r#" + /// ``` + /// extern crate b; + /// ``` + pub fn foo() {} + "#) + .file("tests/foo.rs", ""); + + assert_that(p.cargo_process("test").arg("--test=foo"), + execs().with_stdout(format!("\ +{compiling} foo v0.0.1 ([..]) +{running} target[..]debug[..]foo[..] + +running 0 tests + +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured + +", compiling = COMPILING, running = RUNNING))); +}); -- 2.30.2